package com.smxy.daydayup.pojo.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.smxy.daydayup.util.tree.DataTree;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.codec.digest.MurmurHash3;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @team daydayup
 * @time 2021/12/13 13:06
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("讨论信息实体类")
public class TalkInfo implements DataTree<TalkInfo> {

    private Long courseTalkId;
    private String courseTalkNumber;
    private String courseTalkTitle;
    private String courseTalkContent;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime gmtCreate;
    private int great;
    private String userHead;
    private String userName;

    List<TalkInfo> children;
    @Override
    public Integer getId() {
        return courseTalkTitle != null? MurmurHash3.hash32x86(courseTalkNumber.getBytes())
                : MurmurHash3.hash32x86(("SUB" + courseTalkId).getBytes());
    }

    @Override
    public void setId(Integer id) {

    }

    @Override
    public Integer getParentId() {
        return courseTalkTitle != null? null: MurmurHash3.hash32x86(courseTalkNumber.getBytes());
    }

    @Override
    public void setParentId(Integer parentId) {

    }

    @Override
    public void setChildren(List<TalkInfo> children) {
        this.children = children;
    }

    @Override
    public List<TalkInfo> getChildren() {
        return this.children;
    }
}
